-- Rank: nil to ignore to spell rank.
-- Rand can be empty("") for spells that do not have ranks
function TMacros:HasAction(SlotId, SpellName, Rank)
    if not SpellName then return HasAction(SlotId) end

    TMacros.ToolTip:ClearLines()
	TMacros.ToolTip:SetOwner(WorldFrame, "ANCHOR_NONE")
	TMacros.ToolTip:SetAction(SlotId)

	local name = TMacros.NameText:GetText()
    local rank = TMacros.RankText:GetText()
	
    return name == SpellName and ((not Rank) or rank == Rank)
end

function TMacros:PlaceAction(SlotId, SpellName, Rank)
	if not self:HasAction(SlotId, SpellName, Rank) then
		local id = GetSpellIndex(SpellName, Rank)
		if id then 
			PickupSpell(id, BOOKTYPE_SPELL)
			PlaceAction(SlotId)
			ClearCursor()
			return 1
		end
	end
    return nil
end

-- Check if an action spell will be ready within a period of time.
function TMacros:ActionReady(SlotId, Time)
    if not self:HasAction(SlotId) then return nil end
	local wait, now, s, d = Time or 0, GetTime(), GetActionCooldown(SlotId)
	return s == 0 or s + d < now + wait
end